//index.js
//获取应用实例
const app = getApp()
let Axios = require('../../common/js/ajax.js'); //引入Axios方法
let Mtils = require('../../common/js/Mtils.min.js');
Mtils = Mtils.Mtils
var page = 1;
var switch_p = true
Page({
	data: {
		openid: '',
		shopName: '',
		shopAvatarUrl: '',
		curentNav: 2, //当前导航
		store_id: 0,
		quota: {},
		detailed: [],
		isIpx:app.globalData.isIpx?true:false
	},
	//事件处理函数	
	onLoad: function(e) {
		var _this = this;
		this.load = this.selectComponent("#loading");
		this.uid = app.globalData.uid || ''
		this.Md5 = Mtils.security.hex_md5(this.uid) + app.globalData.secret;
		this.Md5 = Mtils.security.hex_md5(this.Md5);
		this.timesp = Mtils.now();
		this.setData({
			store_id: e.id
		})
		Axios.get(app.globalData.baseUrl + 'App/Capital/Cash/bond', {
			uid: this.uid,
			time: this.timesp,
			sign: this.Md5,
			store_id: this.data.store_id
		}, (res) => {
			console.log(res)
			if (res.status == 1) {
				var data = res.info
				_this.setData({
					quota: data,
					detailed: data.list
				})
				_this.load.loadIng()
			} else {
				_this.showModal(res)
			}
		})
	},
	onReady: function() {
		wx.setNavigationBarTitle({
			title: '保证金'
		})
	},
	showModal: function(error) {
		wx.showModal({
			content: error.msg,
			showCancel: false,
		})
	},
	onReachBottom: function() {
		var _this = this;
		wx.showLoading({
			title: '玩命加载中',
		})
		if (switch_p) {
			switch_p = false
			page = page + 1;
			Axios.get(app.globalData.baseUrl + 'App/Capital/Cash/bond?p=' + page, {
				uid: this.uid,
				time: this.timesp,
				sign: this.Md5,
				store_id: this.data.store_id
			}, (res) => {
				console.log(res)
				if (res.status == 1) {
					var data = res.info
					var temp = _this.data.detailed.concat(data.list)
					_this.setData({
						quota: data,
						detailed: temp
					})
					switch_p = true
					wx.hideLoading();
				} else {
					_this.showModal(res)
				}
			})
		}
	}
})
